/*
 *
 * Copyright (c) 2020 The Raptor Authors. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef RAPTOR_LITE_SRC_COMMON_COMMON_H_
#define RAPTOR_LITE_SRC_COMMON_COMMON_H_

#include <stddef.h>
#include <stdint.h>

#include "raptor-lite/impl/endpoint.h"
#include "raptor-lite/utils/status.h"

namespace raptor {

class Slice;
struct EventDetail;

namespace internal {

constexpr int kErrorEvent    = 1;
constexpr int kSendEvent     = 1 << 1;
constexpr int kRecvEvent     = 1 << 2;
constexpr int kConnectEvent  = 1 << 3;
constexpr int kAcceptEvent   = 1 << 4;
constexpr int kMaxEventValue = kAcceptEvent + 1;

class EventReceivingService {
public:
    virtual ~EventReceivingService() {}
    virtual void OnEventProcess(EventDetail *detail) = 0;
};

class NotificationTransferService {
public:
    virtual ~NotificationTransferService() {}
    virtual void OnDataReceived(Endpoint ep, const Slice &s) = 0;
    virtual void OnClosed(Endpoint ep, raptor_error desc)    = 0;
    virtual void OnHeartBeat(Endpoint ep)                    = 0;
};

constexpr int TID_HEARTBEAT        = 1001; // for heartbeat
constexpr int TID_TIMEOUT_CHECKING = 1002; // for receiving timeout checking

} // namespace internal

class EndpointClosedHandler;
class HeartbeatHandler;
class ProtocolHandler;
class MessageHandler;

struct Option {
    int recv_send_threads;
    int core_event_threads;
    int init_container_size;
    int max_container_size;
    int max_receiving_interval;
    int check_receiving_interval;
    MessageHandler *msg_handler;
    ProtocolHandler *proto_handler;
    HeartbeatHandler *heartbeat_handler;
    EndpointClosedHandler *closed_handler;
};
} // namespace raptor

#endif // RAPTOR_LITE_SRC_COMMON_COMMON_H_
